//----------------------------------*-C++-*----------------------------------//
/*!
 * \file   slabtran.cc
 * \author Jeremy Roberts
 * \date   08/26/2010
 * \brief  Driver for Slabtran code
 * \note   Copyright (C) 2011 Jeremy Roberts
 */
//---------------------------------------------------------------------------//
// $Rev::                                               $:Rev of last commit
// $Author::                                            $:Author of last commit
// $Date::                                              $:Date of last commit
//---------------------------------------------------------------------------//

#include <iostream>
#include <iomanip>

#include "tran/Definitions.hh"
#include "tran/Traits.hh"
#include "tran/SlabtranInput.hh"
#include "tran/SlabtranProblem.hh"
#include "tran/SlabtranProblem.t.hh"
#include "tran/DD_1D_Equations.hh"
#include "../utilities/GenException.hh"

using namespace std;

//---------------------------------------------------------------------------//

template<class Equations, class D>
void run(slabtran::SlabtranInput &input)
{
	using namespace slabtran;

	//--------------------------------------------------------------------------
	// problem
	slabtran::SlabtranProblem<Equations, D> *problem[ input.numel() ];

	for (int i = 0; i < input.numel(); ++i)
	{
		cout << " ================= PROBLEM "
		     << i+1 << " ================= " << endl;
		problem[i] = new SlabtranProblem<Equations, D>( input, i );
	}

//    cout << endl;
//    cout << "Slabtran setup complete, ready to solve using the "
//         << endl;
//    cout << std::setw(4) << Equations::name()
//         << " spatial differencing option." << endl;
//    cout << "------------------------------------------"
//    	 << "-----------------------------------" << endl << endl;

//    // solve the problem
//    problem[i].solve();
//    // output the varscl file
//    problem[i].output();
//    // stop the timer
//    timer.stop();
//    double total = timer.TIMER_CLOCK();
//    nemesis::global_barrier();
//    // >>> END
//    // output the timing
//    problem[i].timing(out, total);
//    out.precision(4);
//    if (nemesis::node() == 0)
//        out << "\n" << "Total execution time : " << std::scientific
//            << total << " seconds." << "\n";
}

int main(int argc, char *args[])
{
	//-------------------------------------------------------------------------
	// initialize PETSc
	// PetscInitialize(&argc,&args,PETSC_NULL,PETSC_NULL);

	//-------------------------------------------------------------------------
	// input (Note: I give an absolute location since I'm building w/ Eclipse)
    cout << " WARNING: hard coded RNG grammar!! See ~ line 73 in slabtran.cc "
         << endl;
	slabtran::SlabtranInput
		input("/home/robertsj/Research/serment/serment/slabtran/slabtran.rng");
	if ( argc < 2 )
	{
		throw GenException(__LINE__,__FILE__,
				"Need at least 1 command line argument.");
	}
	input.readInput( args[1] );

	//-------------------------------------------------------------------------
	// set up the problem manager; templated w/ equation type and dimension
	if ( input.spacedim() == 1 )
	{
		run< slabtran::DD_1D_Equations, slabtran::Dimension<1> >(input);
	}
	else // other dimensions need to be implemented
	{
		throw GenException(__LINE__,__FILE__,
						"Illegal problem spatial dimension.");
	}

	cout << endl;
	cout << "  .... game over .... " << endl;
	//PetscFinalize();
	return 0;
}

//---------------------------------------------------------------------------//
//                 end of slabtran.cc
//---------------------------------------------------------------------------//

